package com.lovo.psc.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lovo.psc.bean.TendersBean;
import com.lovo.psc.mapper.ITenderMapper;
import com.lovo.psc.service.ITenderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class TenderServiceImpl implements ITenderService {
    @Autowired
    private ITenderMapper tenderMapper;
    @Override
    public Page<TendersBean> findAll(int id,int pageNO) {
        return tenderMapper.selectPage(new Page<>(pageNO,3),null);
    }

    @Override
    public List<TendersBean> findByStatus(int status) {
        QueryWrapper<TendersBean>qw=new QueryWrapper<>();
        qw.eq("t_status",status);
        List<TendersBean> tendersBeans = tenderMapper.selectList(qw);
        return tendersBeans;
    }

    @Override
    public TendersBean findById(int tendersId) {
        return tenderMapper.selectById(tendersId);
    }

    @Override
    public void updateStatus(int id, int status) {
        TendersBean tendersBean = tenderMapper.selectById(id);
        tendersBean.setStatus(status);
        tenderMapper.updateById(tendersBean);
    }

    @RabbitListener(queues = "queueRFp")
    public void test(String json){
        TendersBean tendersBean= JSONObject.parseObject(json,TendersBean.class);
        tenderMapper.insert(tendersBean);
        System.out.println(tendersBean);
    }
}
